{{include file="public/header" /}}

<!-- right content start  -->
<div class="content-right">
    <div class="content">
        <!-- form start -->
        <form class="am-form form-validation form-search" method="post" action="{{:MyUrl('admin/order/orderDelivery')}}" request-type="form">
            <div class="thin">
                <div class="am-input-group am-input-group-sm am-fl so">
                    <input type="text" autocomplete="off" name="keywords" class="am-radius" placeholder="订单号/姓名/手机/地址/快递单号" value="{{if !empty($params.keywords)}}{{$params.keywords}}{{/if}}" />
                    <span class="am-input-group-btn">
                        <button class="am-btn am-btn-default am-radius" type="submit" data-am-loading="{spinner:'circle-o-notch', loadingText:'搜索中...'}">搜索</button>
                    </span>
                </div>
                <label class="am-fl thin_sub more-submit">
                    更多筛选条件
                    {{if isset($params['is_more']) and $params['is_more'] eq 1}}
                    <input type="checkbox" name="is_more" value="1" id="is_more" checked />
                    <i class="am-icon-angle-up"></i>
                    {{else /}}
                    <input type="checkbox" name="is_more" value="1" id="is_more" />
                    <i class="am-icon-angle-down"></i>
                    {{/if}}
                </label>
            </div>
            <table class="so-list more-where {{if !isset($params['is_more'])}}none{{/if}}">
                <tbody>

                    <tr>

                        <td class="time">
                            <span>时间：</span>
                            <span>
                                <input type="text" autocomplete="off" name="time_start" class="am-form-field am-input-sm am-radius Wdate" placeholder="起始时间" value="{{if !empty($params.time_start)}}{{$params.time_start}}{{/if}}" data-validation-message="日期格式有误" onclick="WdatePicker({firstDayOfWeek: 1, dateFmt: 'yyyy-MM-dd'})" autocomplete="off" /><i class="am-icon-calendar"></i>
                            </span>
                            <em class="text-grey">~</em>
                            <span>
                                <input type="text" autocomplete="off" name="time_end" class="am-form-field am-input-sm am-radius Wdate" placeholder="结束时间" value="{{if !empty($params.time_end)}}{{$params.time_end}}{{/if}}" pattern="^[0-9]{4}-[0-9]{2}-[0-9]{2}$" data-validation-message="日期格式有误" onclick="WdatePicker({firstDayOfWeek: 1, dateFmt: 'yyyy-MM-dd'})" autocomplete="off" /><i class="am-icon-calendar"></i>
                            </span>
                        </td> 
                        <td>
                            <button type="submit" class="am-btn am-btn-primary am-radius am-btn-xs btn-loading-example" data-am-loading="{spinner:'circle-o-notch', loadingText:'搜索中...'}">搜索</button>
                            <a href="{{:MyUrl('admin/order/index')}}" class="am-btn am-btn-warning am-radius am-btn-sm reset-submit">清除条件</a>
                        </td>
                    </tr>				 
                </tbody>
            </table>
        </form>
        <!-- form end -->

        <!-- operation start -->
        <div class="am-g m-t-15"> 
             <button id='piliang' class="am-btn am-btn-secondary am-btn-xs am-radius am-icon-send-o  am-icon-file-excel-o submit-delivery" data-url="{{:MyUrl('admin/order/delivery')}}" data-id="" data-user-id="" data-express-id="" data-am-modal="{target: '#order-delivery-popup'}"> 批量打印发货</button>  
        </div>
        <!-- operation end -->

        <!-- list start -->
        <table class="am-table am-table-striped am-table-hover am-text-middle m-t-10">
            <thead>
                <tr>
                     <th><input class='dh' type="checkbox" id="CheckAll">&nbsp;全选</th>
                    <th class="am-hide-sm-only th-goods">基础信息</th>
                    <th class="am-hide-md-down">用户信息</th>
                    <th class="am-hide-sm-only th-receive-address">收件信息</th>
                    <th class="am-hide-md-down">快递信息</th>
                    <th>订单状态</th>
                    <th>订单金额(元)</th>
                    <th class="am-hide-sm-only">扩展数据</th>
                    <th>更多</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {{if !empty($data_list)}}
                {{foreach $data_list as $v}}
                <tr id="data-list-{{$v.id}}" {{if $v['pay_status'] eq 1 and $v['total_price'] gt $v['pay_price']}}class="am-danger"{{/if}}>
                   <td><input type="checkbox" class="dh" name='ids[]' value="{{$v.id}}" ></td>
                    <td class="am-hide-sm-only">
                        
                        <div class="order-no">{{$v.order_no}}</div>
                        {{foreach $v.items as $vs}}
                        <div class="goods-item">
                            <div class="base">
                                <a href="{{:MyUrl('index/goods/index', ['id'=>$vs['goods_id']])}}" target="_blank" title="{{$vs.title}}">
                                    <img src="{{$vs['images']}}" class="am-img-thumbnail am-radius goods-images am-hide-sm-only" />
                                </a>
                                <a href="{{:MyUrl('index/goods/index', ['id'=>$vs['goods_id']])}}" target="_blank" title="{{$vs.title}}" {{if !empty($vs['title_color'])}} style="color:{{$vs.title_color}};" {{/if}} >{{$vs.title}}</a>
                            </div>( {{$vs.warehouse_name}} ) 
                            <div class="other">
                                <span class="fl fs-12">
                                    {{if !empty($vs.spec_text)}}
                                    {{$vs.spec_text}}
                                    {{/if}}
                                </span>
                                {{if $vs['returned_quantity'] gt 0 or $vs['refund_price'] gt 0}}
                                <span class="am-text-danger am-fr am-margin-left-sm">已退 {{$vs.returned_quantity}} / {{$vs.refund_price}}</span>
                                {{/if}}
                                <span class="am-fr">{{$vs.price}}x{{$vs.buy_number}}</span>
                            </div>
                        </div>
                        {{/foreach}}
                        <div class="goods-item">{{$v.describe}}</div>
                    </td>
                    <td class="user-info am-hide-md-down">
                        {{if !empty($v['user'])}}
                        <img src="{{$v.user.avatar}}" alt="{{$v.user.user_name_view}}" class="am-img-thumbnail am-radius am-align-left" />
                        <ul class="user-base">
                            <li>名称：{{if empty($v['user']['username'])}}<span class="cr-ccc">未填写</span>{{else /}}{{$v.user.username}}{{/if}}</li>
                            <li>昵称：{{if empty($v['user']['nickname'])}}<span class="cr-ccc">未填写</span>{{else /}}{{$v.user.nickname}}{{/if}}</li>
                            <li>手机：{{if empty($v['user']['mobile'])}}<span class="cr-ccc">未填写</span>{{else /}}{{$v.user.mobile}}{{/if}}</li>
                            <li>邮箱：{{if empty($v['user']['email'])}}<span class="cr-ccc">未填写</span>{{else /}}{{$v.user.email}}{{/if}}</li>
                        </ul>
                        {{else /}}
                        用户信息异常
                        {{/if}}
                    </td>
                    <td class="am-hide-sm-only">
                        {{$v.receive_name}}<br />
                        {{$v.receive_tel}}<br />
                        {{$v.receive_province_name}}<br />
                        {{$v.receive_city_name}}<br />
                        {{$v.receive_county_name}}<br />
                        {{$v.receive_address}}
                    </td>
                    <td class="am-hide-md-down">
                        {{if empty($v['express_name'])}}
                        <span class="cr-ddd">未填写</span>
                        {{else /}}
                        {{$v.express_name}}<br />{{$v.express_number}}
                        {{/if}}
                    </td>
                    <td>
                        <span class="block">{{$v.status_name}}</span>

                        {{if $v['pay_status'] eq 1}}
                        <span class="block am-text-success fs-12">{{$v.pay_status_name}}</span>
                        {{elseif $v['pay_status'] gt 1 /}}
                        <span class="block am-text-danger fs-12">{{$v.pay_status_name}}</span>
                        {{else /}}
                        <span class="block fs-12">{{$v.pay_status_name}}</span>
                        {{/if}}
                        {{if $v['user_is_delete_time'] neq 0}}
                        <span class="block am-text-warning fs-12">用户已删除</span>
                        {{/if}}
                    </td>
                    <td>
                        金额：{{$v.price}}<br />
                        增加：{{$v.increase_price}}<br />
                        优惠：{{$v.preferential_price}}<br />
                        总价：{{$v.total_price}}<br />
                        支付：{{$v.pay_price}}<br />
                        退款：{{if $v['refund_price'] gt 0}}<span class="am-text-danger">{{$v.refund_price}}</span>{{else /}}{{$v.refund_price}}{{/if}}
                    </td>
                    <td class="am-hide-sm-only">
                        {{if empty($v['extension_data'])}}
                        <span class="cr-ddd">无</span>
                        {{else /}}
                        {{foreach $v.extension_data as $extk=>$ext}}
                        {{if $extk gt 0}}<br />{{/if}}
                        {{$ext.name}} [{{$ext.tips}}]
                        {{/foreach}}
                        {{/if}}
                    </td>
                    <td>
                        <span class="am-icon-caret-down c-p" data-am-modal="{target: '#my-popup{{$v.id}}'}"> 查看更多</span>
                        <div class="am-popup am-radius" id="my-popup{{$v.id}}">
                            <div class="am-popup-inner">
                                <div class="am-popup-hd">
                                    <h4 class="am-popup-title">详情内容</h4>
                                    <span data-am-modal-close class="am-close">&times;</span>
                                </div>
                                <div class="am-popup-bd">
                                    <dl class="dl-content">
                                        <dt>订单号</dt>
                                        <dd>{{if empty($v['order_no'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.order_no}}{{/if}}</dd>

                                        <dt>基础信息</dt>
                                        <dd>
                                            {{foreach $v.items as $vs}}
                                            <div class="goods-item">
                                                <div class="base">
                                                    <a href="{{:MyUrl('index/goods/index', ['id'=>$vs['goods_id']])}}" target="_blank" title="{{$vs.title}}">
                                                        <img src="{{$vs['images']}}" class="am-img-thumbnail am-radius goods-images am-hide-sm-only" />
                                                    </a>
                                                    <a href="{{:MyUrl('index/goods/index', ['id'=>$vs['goods_id']])}}" target="_blank" title="{{$vs.title}}" {{if !empty($vs['title_color'])}} style="color:{{$vs.title_color}};" {{/if}} >{{$vs.title}}</a>
                                                </div>
                                                <div class="other">
                                                    <span class="fl fs-12">
                                                        型号：
                                                        {{if !empty($vs.model)}}
                                                        {{$vs.model}}
                                                        {{/if}}
                                                    </span>
                                                    <span class="fl fs-12">
                                                        规格：
                                                        {{if !empty($vs.spec_text)}}
                                                        {{$vs.spec_text}}
                                                        {{/if}}
                                                    </span>
                                                    <span class="fl fs-12">
                                                        重量：{{$vs.spec_weight}}
                                                    </span>
                                                    <span class="fl fs-12">
                                                        编码：{{$vs.spec_coding}}
                                                    </span>
                                                    {{if $vs['returned_quantity'] gt 0 or $vs['refund_price'] gt 0}}
                                                    <span class="am-text-danger am-fr am-margin-left-sm">已退 {{$vs.returned_quantity}} / {{$vs.refund_price}}</span>
                                                    {{/if}}
                                                    <span class="fr">{{$vs.price}}x{{$vs.buy_number}}</span>
                                                </div>
                                            </div>
                                            {{/foreach}}
                                            <div class="goods-item">{{$v.describe}}</div>
                                        </dd>

                                        <dt>用户信息</dt>
                                        <dd class="user-info">
                                            {{if !empty($v['user'])}}
                                            <img src="{{$v.user.avatar}}" alt="{{$v.user.user_name_view}}" class="am-img-thumbnail am-radius am-align-left" />
                                            <ul class="user-base">
                                                <li>名称：{{if empty($v['user']['username'])}}<span class="cr-ccc">未填写</span>{{else /}}{{$v.user.username}}{{/if}}</li>
                                                <li>昵称：{{if empty($v['user']['nickname'])}}<span class="cr-ccc">未填写</span>{{else /}}{{$v.user.nickname}}{{/if}}</li>
                                                <li>手机：{{if empty($v['user']['mobile'])}}<span class="cr-ccc">未填写</span>{{else /}}{{$v.user.mobile}}{{/if}}</li>
                                                <li>邮箱：{{if empty($v['user']['email'])}}<span class="cr-ccc">未填写</span>{{else /}}{{$v.user.email}}{{/if}}</li>
                                            </ul>
                                            {{else /}}
                                            用户信息异常
                                            {{/if}}
                                        </dd>

                                        <dt>收件信息</dt>
                                        <dd>
                                            {{if empty($v['receive_address'])}}
                                            <span class="cr-ddd">未填写</span>
                                            {{else /}}
                                            {{$v.receive_name}}<br />
                                            {{$v.receive_tel}}<br />
                                            {{$v.receive_province_name}}
                                            {{$v.receive_city_name}}
                                            {{$v.receive_county_name}}
                                            {{$v.receive_address}}
                                            {{/if}}
                                        </dd>

                                        <dt>快递信息</dt>
                                        <dd>{{if empty($v['express_name'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.express_name}}<br />{{$v.express_number}}{{/if}}</dd>

                                        <dt>客户端类型</dt>
                                        <dd>{{if empty($v['client_type_name'])}}<span class="cr-ddd">未知</span>{{else /}}<span class="am-badge am-badge-secondary am-radius">{{$v.client_type_name}}{{/if}}</span></dd>

                                        <dt>支付状态</dt>
                                        <dd>{{if empty($v['pay_status_name'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.pay_status_name}}{{/if}}</dd>

                                        <dt>订单状态</dt>
                                        <dd>{{if empty($v['status_name'])}}<span class="cr-ddd">未设置</span>{{else /}}{{$v.status_name}}{{/if}}</dd>

                                        <dt>支付方式</dt>
                                        <dd>{{if empty($v['payment_name'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.payment_name}}{{/if}}</dd>

                                        <dt>用户备注</dt>
                                        <dd>{{if empty($v['user_note'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.user_note}}{{/if}}</dd>

                                        <dt>订单金额(元)</dt>
                                        <dd>
                                            {{if empty($v['price'])}}
                                            <span class="cr-ddd">未填写</span>
                                            {{else /}}
                                            金额：{{$v.price}}<br />
                                            增加：{{$v.increase_price}}<br />
                                            优惠：{{$v.preferential_price}}<br />
                                            总价：{{$v.total_price}}<br />
                                            支付：{{$v.pay_price}}<br />
                                            退款：{{if $v['refund_price'] gt 0}}<span class="am-text-danger">{{$v.refund_price}}</span>{{else /}}{{$v.refund_price}}{{/if}}
                                            {{/if}}
                                        </dd>

                                        <dt>扩展数据</dt>
                                        <dd>
                                            {{if empty($v['extension_data'])}}
                                            <span class="cr-ddd">无</span>
                                            {{else /}}
                                            {{foreach $v.extension_data as $extk=>$ext}}
                                            {{if $extk gt 0}}<br />{{/if}}
                                            {{$ext.name}} [{{$ext.tips}}]
                                            {{/foreach}}
                                            {{/if}}
                                        </dd>

                                        <dt>购买数量</dt>
                                        <dd>{{if empty($v['buy_number_count'])}}<span class="cr-ddd">未知</span>{{else /}}{{$v.buy_number_count}}{{/if}}</dd>

                                        <dt>退货数量</dt>
                                        <dd>{{if empty($v['returned_quantity'])}}<span class="cr-ddd">未退货</span>{{else /}}{{$v.returned_quantity}}{{/if}}</dd>

                                        <dt>退款金额</dt>
                                        <dd>{{if empty($v['refund_price']) or $v['refund_price'] elt 0.00}}<span class="cr-ddd">未退款</span>{{else /}}<span class="am-text-danger">{{$v.refund_price}}{{/if}}</span></dd>

                                        <dt>确认时间</dt>
                                        <dd>{{if empty($v['confirm_time'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.confirm_time}}{{/if}}</dd>

                                        <dt>支付时间</dt>
                                        <dd>{{if empty($v['pay_time'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.pay_time}}{{/if}}</dd>

                                        <dt>发货时间</dt>
                                        <dd>{{if empty($v['delivery_time'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.delivery_time}}{{/if}}</dd>

                                        <dt>完成时间</dt>
                                        <dd>{{if empty($v['collect_time'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.collect_time}}{{/if}}</dd>

                                        <dt>取消时间</dt>
                                        <dd>{{if empty($v['cancel_time'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.cancel_time}}{{/if}}</dd>

                                        <dt>关闭时间</dt>
                                        <dd>{{if empty($v['close_time'])}}<span class="cr-ddd">未填写</span>{{else /}}{{$v.close_time}}{{/if}}</dd>

                                        <dt>创建时间</dt>
                                        <dd>{{$v.add_time}}</dd>

                                        <dt>更新时间</dt>
                                        <dd>{{$v.upd_time}}</dd>
                                    </dl>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td class="view-operation">
                       
                        {{if $v['status'] eq 2}}
                        <button class="am-btn am-btn-secondary am-btn-xs am-radius am-icon-send-o am-btn-block submit-delivery" data-url="{{:MyUrl('admin/order/delivery')}}" data-id="{{$v.id}}" data-user-id="{{$v.user_id}}" data-express-id="{{$v.express_id}}" data-am-modal="{target: '#order-delivery-popup'}"> 发货</button>
                        {{/if}}
                  

                        <!-- 订单列表操作钩子 -->
                        {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}}
                        <div class="plugins-tag">
                            <span>plugins_view_admin_order_list_operation</span>
                        </div>
                        {{/if}}
                        {{php}}
                        $hook_name = 'plugins_view_admin_order_list_operation';
                        $hook_data = Hook::listen($hook_name, ['hook_name'=>$hook_name, 'is_backend'=>true, 'id'=>$v['id'], 'data'=>$v]);
                        if(!empty($hook_data) && is_array($hook_data))
                        {
                        foreach($hook_data as $hook)
                        {
                        if(is_string($hook) || is_int($hook))
                        {
                        echo htmlspecialchars_decode($hook);
                        }
                        }
                        }
                        {{/php}}
                    </td>
                </tr>
                {{/foreach}}
                {{/if}}
            </tbody>
        </table>
        {{if empty($data_list)}}
        <div class="table-no"><i class="am-icon-warning"></i> 没有相关数据</div>
        {{/if}}
        <!-- list end -->

        <!-- 发货弹窗 -->
        <div class="am-popup" id="order-delivery-popup">
            <div class="am-popup-inner">
                <div class="am-popup-hd">
                    <h4 class="am-popup-title">发货操作</h4>
                    <span data-am-modal-close class="am-close">&times;</span>
                </div>
                <div class="am-popup-bd">
                    <form class="am-form form-validation-delivery " method="post" action="{{:MyUrl('admin/order/delivery')}}" request-type="ajax-reload">
                        <!-- 支付方式 -->
                        <div class="business-item">
                            <h3>选择快递</h3>
                            {{if !empty($express_list)}}
                            <ul class="express-list" data-type="express">
                                {{foreach $express_list as $express}}
                                {{if $express.is_enable eq 1}}
                                    <li class="express-items-{{$express.id}}" data-value="{{$express.id}}">
                                        {{if !empty($express.icon)}}
                                        <img src="{{$express.icon}}" />
                                        {{/if}}
                                        <span>{{$express.name}}</span>
                                        <i class="icon-active"></i>
                                    </li>
                                {{/if}}
                                {{/foreach}}
                            </ul>
                            {{/if}}
                            {{if empty($express_list)}}
                            <div class="table-no"><i class="am-icon-warning"></i> 没有快递方式</div>
                            {{/if}}
                        </div>

<!--                        <div class="am-form-group">
                            <label>快递单号</label>
                            <input type="text" autocomplete="off"   id="idss" name="express_number" placeholder="快递单号" minlength="1" data-validation-message="请填写快递单号" class="am-radius" required />
                        </div>-->
                        <div class="am-form-group am-form-group-refreshing">
                            <input type="hidden" id="ids" name="id" value="0" />
                            <input type="hidden" id="express_id" name="express_id" value="0" />
                          
                            <button type="submit" class="am-btn am-btn-primary am-radius btn-loading-example am-btn-sm am-btn-block" data-am-loading="{loadingText:'处理中...'}">确认</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
  
        <!-- page start -->
        {{if !empty($data_list)}}
        {{$page_html|raw}}
        {{/if}}
        <!-- page end -->
    </div>
</div>
<!-- right content end  -->

<!-- footer start -->
{{include file="public/footer" /}}
<!-- footer end -->

<script> 

                                        $("#CheckAll").bind("click", function () {
                                            $("input[name='ids[]']").prop("checked", this.checked);
                                        });


                                        $(".dh").click(function () {
                                        
                                                var checks = $("input[name='ids[]']:checked");
                                                if (checks.length == 0) {
                                                    alert('未选中任何项！');
                                                    return false;
                                                }
                                                //将获取的值存入数组
                                                var checkData = new Array();
                                                checks.each(function () {
                                                    checkData.push($(this).val());
                                                });
                                                    ids =  checkData.toString(); //多条数据
                                        $("#ids").val(ids);
                                     
                                        });

</script>